package com.shiyun.generator;

import com.shiyun.model.MainTemplateConfig;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

public class MainGenerator {
    public static void doGenerator(Object model) throws IOException, TemplateException {
        String projectPath = System.getProperty("user.dir");
        File parentFile = new File(projectPath).getParentFile();
        //输入路径
        String inputPath = new File(parentFile,"code-generator-demo-projects/acm-template").getAbsolutePath();
        String outputPath = projectPath;
        //生成静态文件 从模板目录拷贝到当前项目
        StaticGenerator.copyFileByHutool(inputPath,outputPath);
        //生成动态文件 替换拷贝过来的静态文件
        String inputDynamicFilePath = projectPath +  File.separator + "src/main/resources/templates/MainTemplate.java.ftl";
        String outputDynamicFilePath = outputPath + File.separator + "acm-template/src/com/shiyun/acm/MainTemplate.java";
        DynamicGenerator.doGenerator(inputDynamicFilePath,outputDynamicFilePath,model);
    }

    public static void main(String[] args) throws IOException, TemplateException {
        MainTemplateConfig mainTemplateConfig = new MainTemplateConfig();

        doGenerator(mainTemplateConfig);
    }
}
